import request from "@/utils/request.js";
import {ref} from "vue";

export function getPageByUnit(params) {
    return request({
        url: "/word_primary/listByUnit",
        method: "get",
        params: params
    })
}

export function putStudyData(params) {
    return request({
        url: "/word_primary/putStudyData",
        method: "post",
        data: params
    })
}

export function putWriteRecord(params) {
    return request({
        url: "/word_primary/putWriteRecord",
        method: "post",
        data: params
    })
}

export function getWriteRecord(params) {
    return request({
        url: "/word_primary/getWriteRecord",
        method: "get",
        params: params
    })
}

export function listStudyPage(params) {
    return request({
        url: "/word_primary/listStudyPage",
        method: "get",
        params: params
    })
}

export function putStudyList(params) {
    return request({
        url: "/word_primary/putStudyList",
        method: "post",
        data: params
    })
}

export function putTestList(params) {
    return request({
        url: "/word_primary/putTestList",
        method: "post",
        data: params
    })
}

export function getPageUnitTimes(params) {
    return request({
        url: "/word_primary/listUnitTimes",
        method: "get",
        params: params
    })
}

export function getTestDetailsList(params) {
    return request({
        url: "/word_primary/getTestDetail",
        method: "get",
        params: params
    })
}

/**
 * 初中学习列表
 * */
export function getBookType(row) {
    let res = '未分'
    if (row.book.toString().at(5) === '-' && row.book.toString().at(6) === 'A') {
        res = '上册'
    } else if (row.book.toString().at(5) === '-' && row.book.toString().at(6) === 'B') {
        res = '下册'
    }
    return res
}

/**
 * 随机获取学习列表中的任一内容
 * */
export function getRandomContent() {
    let res = []
    let length = bookAndUnitList.value.length;
    let number = Math.ceil(Math.random() * (length - 1));
    let lengthChild = bookAndUnitList.value[number].children.length;
    let numberChild = Math.ceil(Math.random() * (lengthChild - 1));
    // res.push(number,numberChild);
    let arr1 = bookAndUnitList.value[number];
    // res = {0 : arr1.value, 1: arr1.children[numberChild].value}
    res = [arr1.value, arr1.children[numberChild].value]
    return res
}

/**
 * 初中学习列表
 * */
export const bookAndUnitList = ref([
        {
            value: 'book7-A',
            label: '七年级-上册',
            children: [
                {value: 'unit0', label: '开始课'},
                {value: 'unit1', label: '第一课'},
                {value: 'unit2', label: '第二课'},
                {value: 'unit3', label: '第三课'},
                {value: 'unit4', label: '第四课'},
                {value: 'unit5', label: '第五课'},
                {value: 'unit6', label: '第六课'},
                {value: 'unit7', label: '第七课'},
                {value: 'unit1-new', label: '第一课(新课标)'},
                {value: 'unit2-new', label: '第二课(新课标)'},
                {value: 'unit3-new', label: '第三课(新课标)'},
                {value: 'unit4-new', label: '第四课(新课标)'},
                {value: 'unit5-new', label: '第五课(新课标)'},
                {value: 'unit6-new', label: '第六课(新课标)'},
                {value: 'unit7-new', label: '第七课(新课标)'},
            ]
        },
        {
            value: 'book7-B', label: '七年级-下册', children: [
                {value: 'unit0', label: '开始课'},
                {value: 'unit1', label: '第一课'},
                {value: 'unit2', label: '第二课'},
                {value: 'unit3', label: '第三课'},
                {value: 'unit4', label: '第四课'},
                {value: 'unit5', label: '第五课'},
                {value: 'unit6', label: '第六课'},
                {value: 'unit7', label: '第七课'},
                {value: 'unit1-new', label: '第一课(新课标)'},
                {value: 'unit2-new', label: '第二课(新课标)'},
                {value: 'unit3-new', label: '第三课(新课标)'},
                {value: 'unit4-new', label: '第四课(新课标)'},
                {value: 'unit5-new', label: '第五课(新课标)'},
                {value: 'unit6-new', label: '第六课(新课标)'},
                {value: 'unit7-new', label: '第七课(新课标)'},
            ]
        },
        {
            value: 'book8-A', label: '八年级-上册', children: [
                {value: 'unit1', label: '第一课'},
                {value: 'unit2', label: '第二课'},
                {value: 'unit3', label: '第三课'},
                {value: 'unit4', label: '第四课'},
                {value: 'unit5', label: '第五课'},
                {value: 'unit6', label: '第六课'},
                {value: 'unit7', label: '第七课'},
                {value: 'unit8', label: '第八课'},
                {value: 'unit9', label: '第九课'},
                {value: 'unit10', label: '第十课'},
            ]
        },
        {
            value: 'book8-B', label: '八年级-下册', children: [
                {value: 'unit1', label: '第一课'},
                {value: 'unit2', label: '第二课'},
                {value: 'unit3', label: '第三课'},
                {value: 'unit4', label: '第四课'},
                {value: 'unit5', label: '第五课'},
                {value: 'unit6', label: '第六课'},
                {value: 'unit7', label: '第七课'},
                {value: 'unit8', label: '第八课'},
                {value: 'unit9', label: '第九课'},
                {value: 'unit10', label: '第十课'},
            ]
        },
        {
            value: 'book9', label: '九年级', children: [
                {value: 'unit1', label: '第一课'},
                {value: 'unit2', label: '第二课'},
                {value: 'unit3', label: '第三课'},
                {value: 'unit4', label: '第四课'},
                {value: 'unit5', label: '第五课'},
                {value: 'unit6', label: '第六课'},
                {value: 'unit7', label: '第七课'},
                {value: 'unit8', label: '第八课'},
                {value: 'unit9', label: '第九课'},
                {value: 'unit10', label: '第十课'},
                {value: 'unit11', label: '第十一课'},
                {value: 'unit12', label: '第十二课'},
                {value: 'unit13', label: '第十三课'},
                {value: 'unit14', label: '第十四课'},
            ]
        }
    ]
)